Component({
  data: {
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#F7B159",
    // "color": "#999",
    // "backgroundColor": "#fafafa",
    // "selectedColor": "#F7B159",
    // "borderStyle": "white",
    list: [{
      pagePath: "/pages/index/index",
      iconPath: "/image/icon_component.png",
      selectedIconPath: "/image/icon_component_HL.png",
      text: "首页"
    }, {
      pagePath: "/pages/task/index",
      iconPath: "/image/icon_API.png",
      selectedIconPath: "/image/icon_API_HL.png",
      text: "我的任务"
    }, {
      pagePath: "/pages/user/index",
      iconPath: "/image/icon_API.png",
      selectedIconPath: "/image/icon_API_HL.png",
      text: "我的"
    }]
  },
  attached () {
    let tabbarList = wx.getStorageSync('tabbarList')
    if (tabbarList) {
      tabbarList = JSON.parse(tabbarList)
      console.log(tabbarList)
      this.setData({list: tabbarList})
    } else{
      console.log('接口获取')
      // 模拟请求后台tablist数据
      let list1 = [{
        pagePath: "/pages/index/index",
        iconPath: "/image/icon_component.png",
        selectedIconPath: "/image/icon_component_HL.png",
        text: "首页"
      }, {
        pagePath: "/pages/task/index",
        iconPath: "/image/icon_API.png",
        selectedIconPath: "/image/icon_API_HL.png",
        text: "我的任务"
      }, {
        pagePath: "/pages/user/index",
        iconPath: "/image/icon_API.png",
        selectedIconPath: "/image/icon_API_HL.png",
        text: "我的"
      }]
      setTimeout(() => {
        wx.setStorageSync('tabbarList', JSON.stringify(list1))
        this.setData({list: list1})
      }, 3000)
    }
  },
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      wx.switchTab({url})
      // 去掉，解决图标闪烁问题
      // this.setData({
      //   selected: data.index
      // })
    }
  }
})